<template>
  <div>
    <el-button type="primary" @click="dialogVisible=true">添加管理员</el-button>


    <el-dialog title="添加管理员" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
      <p style="display: inline-block;">管理员账号：</p>
      <input type="text" style="" v-model="AdminLoginForm.name" /></br>
      <p style="display: inline-block;">管理员密码：</p>
      <input type="text" style="" v-model="AdminLoginForm.adminPwd" /></br>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="ok">确 定</el-button>
      </span>
    </el-dialog>

    <template>
      <el-table :data="admin" border style="width: 100%">
        <el-table-column fixed prop="name" label="账号" width="100">
        </el-table-column>
        <el-table-column prop="date" label="创建时间" width="100">
        </el-table-column>
        <el-table-column prop="updateTime" label="跟新时间" width="100">
        </el-table-column>
        <el-table-column prop="operator" label="跟新人" width="100">
        </el-table-column>
        <el-table-column label="角色" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.role==0">超管</span>
            <span v-if="scope.row.role==1">普管</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.state==0">启用</span>
            <span v-if="scope.row.state==1">下架</span>
          </template>
        </el-table-column>
     
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button v-if="scope.row.state==0" @click="genAdmin(scope.row.id,1)" type="text" size="small"
              :disabled="scope.row.role==0">禁用</el-button>
            <el-button v-if="scope.row.state==1" @click="genAdmin(scope.row.id,0)" type="text" size="small"
              :disabled="scope.row.role==0">启用</el-button>
            <el-button :disabled="scope.row.role==0" @click="delAdmin(scope.row.id)" type="text"
              size="small">删除</el-button>

          </template>
        </el-table-column>
      </el-table>
      </el-table>
    </template>






  </div>
</template>

<script>
  export default {
    data() {
      return {
        AdminLoginForm: {},
        dialogVisible: false,
        genFORM:{},
        admin: []
      }
    },
    methods: {
      ok() { //添加管理员

        this.$http.post("/platform/adminAccount/addAdmin.admin", this.AdminLoginForm)
          .then(resp => {
            this.goodsPage = resp.data.data
            this.fiadAdmin()
            if (resp.data.code != 200) {
              alert(resp.data.message)
            }
            this.dialogVisible = false

          })
      },
      fiadAdmin() {
        this.$http.post("/platform/adminAccount/findAdmin.admin", this.AdminLoginForm)
          .then(resp => {
            this.admin = resp.data.data



          })

      },
      delAdmin(obj) {
        this.$http.post("/platform/adminAccount/delAdmin.admin?id="+obj)
          .then(resp => {


            this.fiadAdmin()

          })
      },
      delAdmin(obj) {
        this.$http.post("/platform/adminAccount/delAdmin.admin?id="+obj)
          .then(resp => {


            this.fiadAdmin()

          })
      },
      genAdmin(obj,obj1){
        this.genFORM.id=obj
        this.genFORM.state=obj1

        this.$http.post("/platform/adminAccount/genAdmin.admin",this.genFORM)
          .then(resp => {


            this.fiadAdmin()

          })
      }



    },
    created() {
      this.fiadAdmin()
    }
  }
</script>

<style>

</style>
